//
//  KY1009AdvertView.m
//  KYMobClick
//
//  Created by 01 on 16/11/8.
//  Copyright © 2016年 Czj. All rights reserved.
//

#import "KY1009AdvertView.h"

#define TextHeight                  kCurrentScreenWidth(20.)

@interface KY1009AdvertView ()

/**
 定义试图控件
 iconView        头像
 titleLabel      用户名
 textLabel       文本介绍
 imgView         图片
 msgLabel        描述
 btn             下载按钮
 */
@property (nonatomic, strong) UIImageView               *iconView;
@property (nonatomic, strong) UILabel                   *titleLabel;
@property (nonatomic, strong) UILabel                   *textLabel;
@property (nonatomic, strong) UIImageView               *imgView;
@property (nonatomic, strong) UILabel                   *msgLabel;
@property (nonatomic, strong) UIButton                  *btn;
@property (nonatomic, strong) UIButton                  *deleteBtn;

//@property (nonatomic, strong) KYAdvertClickData        *clickData;

@end

@implementation KY1009AdvertView

- (instancetype)init
{
    self = [super init];
    if (self) {
        
        self.iconView = [[UIImageView alloc] init];
        [self addSubview:self.iconView];
        
        self.titleLabel = [[UILabel alloc] init];
        [self addSubview:self.titleLabel];
        
        self.textLabel = [[UILabel alloc] init];
        [self addSubview:self.textLabel];
        
        self.imgView = [[UIImageView alloc] init];
        [self addSubview:self.imgView];
        
        self.msgLabel = [[UILabel alloc] init];
        [self addSubview:self.msgLabel];
        
        self.btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:self.btn];
        
        
        self.deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:self.deleteBtn];
        
//        _clickData = [[KYAdvertClickData alloc] init];
    }
    return self;
}

// 接收数据填充试图
- (void) createContent:(NSDictionary *)dataDic blockHeight:(void (^)(NSInteger))viewHeight
{
    CGFloat iconX = kCurrentScreenWidth(15);
    CGFloat iconY = kCurrentScreenWidth(15);
    CGFloat iconW = kCurrentScreenWidth(40);
    CGFloat iconH = kCurrentScreenWidth(40);
    self.iconView.frame = CGRectMake(iconX, iconY, iconW, iconH);
    self.iconView.layer.masksToBounds = YES;
    self.iconView.layer.cornerRadius = iconW/2;
    self.iconView.layer.borderWidth = .5;
    self.iconView.userInteractionEnabled = YES;
    
    CGFloat titleX = CGRectGetMaxX(self.iconView.frame) + kCurrentScreenWidth(15);
    CGFloat titleY = (iconY*2 + iconH - TextHeight)/2.;
    CGFloat titleW = kDeviceWidth - iconW - iconX - kCurrentScreenWidth(15) * 2;
    CGFloat titleH = TextHeight;
    self.titleLabel.frame = CGRectMake(titleX, titleY, titleW, titleH);
    self.titleLabel.font = kSystemFont(kCurrentScreenWidth(16));
    self.titleLabel.textColor = [UIColor grayColor];
    
    CGFloat textX = iconX;
    CGFloat textY = CGRectGetMaxY(self.iconView.frame) + kCurrentScreenWidth(5);
    CGFloat textW = kDeviceWidth - 2*iconX;
    CGFloat textH = TextHeight;
    self.textLabel.frame = CGRectMake(textX, textY, textW, textH);
    self.textLabel.font = kSystemFont(kCurrentScreenWidth(16));
    self.textLabel.numberOfLines = 0;
    
    CGFloat imgX = iconX;
    CGFloat imgY = CGRectGetMaxY(self.textLabel.frame) + kCurrentScreenWidth(5);
    CGFloat imgW = textW;
    CGFloat imgH = 0;
    self.imgView.frame = CGRectMake(imgX, imgY, imgW, imgH);
    self.imgView.userInteractionEnabled = YES;
    
    CGFloat msgX = iconX;
    CGFloat msgY = CGRectGetMaxY(self.imgView.frame) + kCurrentScreenWidth(15);
    CGFloat msgW = kCurrentScreenWidth(50);
    CGFloat msgH = kCurrentScreenWidth(20);
    self.msgLabel.frame = CGRectMake(msgX, msgY, msgW, msgH);
    self.msgLabel.textColor = [UIColor grayColor];
    self.msgLabel.font = kSystemFont(kCurrentScreenWidth(12));
    
    CGFloat btnX = kDeviceWidth - kCurrentScreenWidth(15) - kCurrentScreenWidth(120);
    CGFloat btnY = CGRectGetMaxY(self.imgView.frame) + kCurrentScreenWidth(10);
    CGFloat btnW = kCurrentScreenWidth(120);
    CGFloat btnH = kCurrentScreenWidth(30);
    self.btn.frame = CGRectMake(btnX, btnY, btnW, btnH);
    [self.btn setTitle:@"立即下载" forState:UIControlStateNormal];
    self.btn.titleLabel.textColor = [UIColor whiteColor];
    [self.btn setBackgroundColor:RGBCOLOR(249, 110, 165)];
    self.btn.layer.cornerRadius = 5.;
    
    self.deleteBtn.frame = CGRectMake(kDeviceWidth-35, 5, 30, 30);
    [self.deleteBtn setTitle:@"X" forState:UIControlStateNormal];
    [self.deleteBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    self.deleteBtn.titleLabel.font = [UIFont systemFontOfSize:17];
    
    _viewHeight = CGRectGetMaxY(self.btn.frame) + kCurrentScreenWidth(15);
}

@end
